//
//  MessageCell.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/8.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit
import SnapKit

class MessageCell: UITableViewCell {
    
    //保存约束的引用
    var heightConstraint:Constraint?

    // MARK: - life cycle
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initBaseLayout()
        layoutPageSubviews()
        self.selectionStyle = .none
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - private method
    func initBaseLayout() {
        self.addSubview(informLabel)
        self.addSubview(singleLine)
        self.addSubview(messageLabel)
        self.addSubview(dateLabel)
    }
    
    func layoutPageSubviews() {
        informLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(14)
            make.top.equalTo(self).offset(14)
            make.width.equalTo(SCREEN_WIDTH-28)
            make.height.equalTo(12)
        }
        
        singleLine.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(0)
            make.top.equalTo(informLabel.snp.bottom).offset(13)
            make.width.equalTo(SCREEN_WIDTH)
            make.height.equalTo(1)
        }
        
        messageLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(14)
            make.top.equalTo(singleLine.snp.bottom).offset(12)
            make.width.equalTo(SCREEN_WIDTH-28)
        }
        
        dateLabel.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(-14)
            make.bottom.equalTo(self.snp.bottom).offset(-16)
            make.width.equalTo(141)
            make.height.equalTo(14)
        }
    }
    
    func configUI(messageArr: [String], indexPath: IndexPath) {
        informLabel.text = "物流通知"
        dateLabel.text = "2016年12月9日 09:39:52"

        messageLabel.text = messageArr[indexPath.section]
        
    }
    
    // MARK: - setters and getters
    var _informLabel: UILabel!
    var informLabel: UILabel {
        if _informLabel == nil {
            _informLabel = UILabel()
            _informLabel.font = UIFont(name: "PingFang-SC-Regular", size: 14)
            _informLabel.textColor = UIColor(hexString: "#666666")
        }
        return _informLabel
    }
    
    var _singleLine: UIView!
    var singleLine: UIView {
        if _singleLine == nil {
            _singleLine = UIView()
            _singleLine.backgroundColor = UIColor(hexString: "#D1D1D1")
        }
        return _singleLine
    }
    
    var _messageLabel: UILabel!
    var messageLabel: UILabel {
        if _messageLabel == nil {
            _messageLabel = UILabel()
            _messageLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
            _messageLabel.textColor = UIColor(hexString: "#999999")
            _messageLabel.numberOfLines = 0
        }
        return _messageLabel
    }
    
    var _dateLabel: UILabel!
    var dateLabel: UILabel {
        if _dateLabel == nil {
            _dateLabel = UILabel()
            _dateLabel.font = UIFont(name: "PingFang-SC-Regular", size: 10)
            _dateLabel.textColor = UIColor(hexString: "#999999")
            _dateLabel.textAlignment = .right
        }
        return _dateLabel
    }
}
